﻿Option Strict On
Option Infer On
Option Explicit On

Imports System
Imports System.Linq
Imports System.Xml.Linq
Imports System.Collections.Generic
Imports GenDotNet.StoredProcModel
Imports <xmlns:orm="http://kadgen.com/KADORM.xsd">

Public Class OrderByData
   Inherits BaseData
   Implements IOrderByData

   Private mColumn As IColumnData

   Public Shared Function Load( _
         ByVal rootdata As RootData, _
         ByVal recSet As IRecordsetData, _
         ByVal elements As IEnumerable(Of XElement)) _
         As IEnumerable(Of IOrderByData)
      Dim list = New List(Of IOrderByData)
      For Each e In elements
         list.Add(New OrderByData(rootdata, recSet, e))
      Next
      Return list
   End Function

   Private Sub New( _
           ByVal rootdata As RootData, _
           ByVal recSet As IRecordsetData, _
           ByVal element As XElement)
      MyBase.New(rootdata, element)
      mColumn = recSet.GetColumn(Element.@Name)
   End Sub

   Private Sub New( _
           ByVal rootdata As RootData, _
           ByVal element As XElement)
      MyBase.New(rootdata, element)
   End Sub

   Public ReadOnly Property Direction() As OrderByDirection Implements IOrderByData.Direction
      Get
         Return ParseOrderByDirection(Element.@SortOrder)
      End Get
   End Property

   Public ReadOnly Property Column() As IColumnData Implements IOrderByData.Column
      Get
         Return mColumn
      End Get
   End Property
End Class
